import axios from 'axios';
import { getVersion } from '../utils/request';
import makeApi from './index';

export const api = {
	query: '/sys/sysUser/getListByPage',
	create: '/sys/sysUser/add',
	remove: '/sys/sysUser/delete',
	update: '/sys/sysUser/update',
	getMenu: '/sys/sysUser/menu',
	getDeatil: '/sys/sysUser/detail',
	updateInfo: '/sys/sysUser/updateInfoPersonal',
	reset: '/sys/sysUser/resetPwd',
	sendVerificationCode: '/sys/sysUser/messageAuthenticationCode',
	forgetReset: '/sys/sysUser/forgetPassword',
	uploadLogo: '/sys/file/upload'
};

const services = makeApi(api);

// 上传系统头像
services.uploadLogo = async function uploadLogo(file, onDownloadProgress) {
	console.log(api.uploadLogo);
	const data = new FormData();
	data.append('file', file, file.name);
	const res = await axios.post(api.uploadLogo, data, {
		onDownloadProgress,
		headers: {
			Authorization: window.localStorage.getItem('access_token'),
			Version: getVersion(api.exportQrcode)
		}
	});
	return res.data;
};

const {
	query,
	create,
	remove,
	update,
	getMenu,
	getDeatil,
	updateInfo,
	reset,
	sendVerificationCode,
	forgetReset,
} = services;

export {
	query,
	create,
	remove,
	update,
	getMenu,
	getDeatil,
	updateInfo,
	reset,
	sendVerificationCode,
	forgetReset,
};
export default services;
